<template>

  <div class="user-container">
    <div class="user-main-area shadow">
      <div class="userinfo-block">
        <el-avatar class="user-icon" :size="100" :src="userInfo.iconUrl"></el-avatar>
        <div class="userinfo-box">
          <div class="top">
            <p class="user-name">{{ userInfo.nickName }}</p>
            <div class="link-box">
              <el-tooltip content="绑定微博" :hide-after="0" placement="top">
                <svg class="icon">
                  <use xlink:href="#icon-weibo"/>
                </svg>
              </el-tooltip>

              <el-tooltip content="绑定微信" :hide-after="0" placement="top">
                <svg class="icon">
                  <use xlink:href="#icon-weixin"/>
                </svg>
              </el-tooltip>
              <el-tooltip content="绑定微信" :hide-after="0" placement="top">
                <svg class="icon">
                  <use xlink:href="#icon-qq"/>
                </svg>
              </el-tooltip>

            </div>
          </div>
          <div class="user-level-box">
            <el-tooltip content="认证用户" :hide-after="0" placement="top">
              <svg class="icon">
                <use xlink:href="#icon-renzhengyonghu"/>
              </svg>
            </el-tooltip>
            <el-tooltip content="lv1 初来乍到" :hide-after="0" placement="top">
              <level-button :level="userInfo.level"/>
            </el-tooltip>

          </div>
          <div class="descriptions">
            <div v-if="userInfo.personDescription">{{ userInfo.personDescription }}</div>
            <span @click="$router.push('/setting')" v-if="!userInfo.personDescription">+你有那些爱好？</span>
            <el-button style="padding: 0 2rem" plain type="primary" @click="$router.push('/setting')">设置</el-button>
          </div>
        </div>
      </div>

      <div class="user-badge-block">
        <svg class="icon">
          <use xlink:href="#icon-badge"/>
        </svg>
        获得徽章{{ 0 }}
      </div>
    </div>

    <div class="user-list-area shadow">
      <div class="list-header">
        <div v-if="!isSearch" class="list-menu">
          <el-menu
              default-active="0"
              mode="horizontal"
              :ellipsis="false"
          >
            <el-menu-item
                :index="index+''"
                v-for="(item,index) in menus"
                :key="item.name"
                @click="$router.push(item.path)"
            >
              {{ item.name }}
            </el-menu-item>
          </el-menu>
        </div>
        <div v-if="isSearch" class="search-title">
          <arrow-left style="width: 1rem;"/>
          <button @click="isSearch = !isSearch ">返回</button>
          <div>搜索文章</div>
        </div>

        <div class="input-content">
          <input placeholder="搜索文章" class="search-input" :class="{'show': isSearch}" type="text">
          <svg class="icon" @click="isSearch = !isSearch">
            <use xlink:href="#icon-search"></use>
          </svg>
        </div>
      </div>

      <div class="user-route-area">
        <router-view></router-view>

      </div>
    </div>
  </div>

</template>

<script setup>
import {useUserStore} from "@/store/userStore.js";
import {storeToRefs} from "pinia";
import LevelButton from "@/views/components/user/LevelButton.vue";
import {ref} from 'vue'
import {ArrowLeft} from "@element-plus/icons-vue";
import UserArticleList from "@/views/components/user/UserArticleList.vue";

const userStore = useUserStore();
const {userInfo} = storeToRefs(userStore);

let isSearch = ref(false)
let menus = ref([
  {name: '文章', path: '/user/articleList'},
  {name: '收藏', path: '/user/favorite'},
  {name: '点赞', path: '/user/like'},
  {name: '关注', path: '/user/follow'},
])
</script>

<style lang="scss" scoped>
@import "@/styles/var";

.user-main-area {
  width: 960px;
  padding: 2rem;
  background-color: $color-board;

  .userinfo-block {
    display: flex;
    justify-content: space-between;
    padding-bottom: 2rem;
    border-bottom: $border;

    //头像旋转
    .user-icon:hover {
      transform: rotate(666turn);
      transition: all 59s cubic-bezier(.34, 0, .84, 1) 1s;
    }

    .userinfo-box {
      width: 80%;

      .top {
        display: flex;
        justify-content: space-between;

        .user-name {
          font-size: 1.5rem;
          font-weight: bold;
        }

        .link-box {
          .icon {
            font-size: 1.2rem;
            margin-left: 1rem;
            cursor: pointer;
          }
        }
      }

      .user-level-box {
        padding: 0.5rem 0;

        .icon {
          font-size: 1rem;
          margin-right: 1rem;
        }
      }

      .descriptions {
        padding: 0.5rem 0;
        display: flex;
        justify-content: space-between;
        align-items: end;

        span {
          color: $color-theme;
          cursor: pointer;
        }
      }
    }
  }

  .user-badge-block {
    padding-top: 1rem;
    vertical-align: center;
  }
}

.user-list-area {
  margin-top: 1rem;
  background-color: $color-board;

  .list-header {
    height: 4rem;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: $border;

    .list-menu {
      //el-menu样式
      :deep(.el-menu) {
        height: auto;
        border-bottom: none;

        .el-menu-item {
          line-height: 1.5rem;
          border: none;

          &:hover {
            background-color: transparent;
          }

          &.is-active:after {
            content: "";
            width: 1rem;
            height: 3px;
            background-color: $color-deep-theme;
            border-radius: 3px;
            position: absolute;
            top: 2rem;
          }

          &.is-active {
            border-bottom: none;
            background-color: transparent;
          }
        }
      }
    }

    .search-title {
      display: flex;
      align-items: center;

      button {
        color: $color-black-text;
        background-color: transparent;
        padding: 0 1rem;
        border-right: $border;
        margin-right: 1rem;

        &:hover {
          color: $color-deep-theme;
        }
      }
    }

    .input-content {
      position: relative;
      display: flex;
      align-items: center;

      .search-input {
        width: 0;

        border: none;
        transition: width 0.5s;

        &.show {
          width: 200px;
          padding: 0.5rem;
          border: $border;
          border-radius: 5px;
          color: $color-black-text;
        }

        &.show:focus {
          outline: none;
          box-shadow: $color-theme 0 0 0 1px inset;
          border: 1px solid transparent;
        }
      }

      .icon {
        font-size: 1.2rem;
        cursor: pointer;
        position: absolute;
        right: 1rem;
      }
    }

  }

  .user-route-area {
    padding: 1rem;
  }
}

.shadow {
  box-shadow: $shadow;
  border-radius: 3px;
}

</style>